package vsvm.data.source;

import java.io.Serializable;
import java.util.ArrayList;

import vsvm.data.model.AbstractAttribute;
import vsvm.data.model.AbstractDataModel;
import vsvm.gui.Environment;
import vsvm.gui.IActionsProvider;
import vsvm.gui.IConfigurable;
import vsvm.gui.IQuickInfoProvider;
import vsvm.gui.forms.CreateDataModelDialog;
import vsvm.gui.forms.RawDataFrame;

public abstract class AbstractDataSource implements IConfigurable, IActionsProvider, 
													IQuickInfoProvider, Serializable {
	protected final static String ACT_CREATEDM = "Create data model...";
	protected final static String ACT_VIEW = "View raw data";
	
	protected ArrayList<AbstractAttribute> attributes;
	protected boolean opened;
	protected String name;
	
	public abstract boolean open();
	
	public abstract void close();
	
	public abstract void reset();
	
	public boolean isOpen() {
		return opened;
	}
	
	public abstract String getRawData();
	
	public abstract void fill(AbstractDataModel model, AbstractAttribute classAttr) throws Exception;
	
	public abstract ArrayList<AbstractAttribute> readAttributes();
	
	public void setAttributes(ArrayList<AbstractAttribute> attr) {
		attributes = attr;
	}
	
	public String getName() { return name; }
	
	public void setName(String name) { this.name = name; }

	public String toString() {
		return name;
	}

	public void executeAction(String action) {
		if (action.equals(ACT_CREATEDM)) {
			CreateDataModelDialog cdmd = new CreateDataModelDialog(
					Environment.getEnvironment().getMainFrame(), this);
			cdmd.setVisible(true);
			return;
		}
		
		if (action.equals(ACT_VIEW)) {
			RawDataFrame f = new RawDataFrame("Raw data view for " + this.getName(), this);
			Environment.getEnvironment().getMainFrame().addWindow(f);
			f.setVisible(true);
			
			return;
		}
		
	}

	public String[] getActions() {
		return new String[] {ACT_CREATEDM,ACT_VIEW};
	}
	
}
